
<jsp:directive.page import="action.AddEventAction"/><%@ taglib prefix="html" uri="/WEB-INF/struts-html.tld" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<%@ page language="java" import="cal.*" %>
<%@ page language="java" import="util.*" %>

<html:form action="SelectEmpl">
	<html:select property="selectedEmpl" onchange="form.submit();">
		<html:options name="emplList" />
	</html:select>
</html:form>

<jsp:useBean id="table" scope="session" class="cal.TableBean" />
<jsp:useBean id="entr" scope="session" class="cal.Entry" />


<%
	table.processRequest(request);
	entr.setDateStr(table.getDate());
	if (table.getProcessError() == false) {
%>


<!-- TOP -->
<CENTER>
<TABLE WIDTH=80% BGCOLOR=white CELLPADDING=15>
<%-- Previous Current and next--%>
<TR>
	<TD ALIGN=CENTER>
	<html:link page="/ViewPlanning.do?date=prev"><bean:message key="cal.prev" /></html:link>

	<TD ALIGN=CENTER><bean:message key="cal.planning" />: <%= table.getDate() %></TD>
	<TD ALIGN=CENTER>
	<html:link page="/ViewPlanning.do?date=next"><bean:message key="cal.next" /></html:link>
</TR>
</TABLE>

<!-- PLANNING TABLE -->
<TABLE WIDTH=80% BGCOLOR=white>
	<TR class="planningheader">
		<TH><bean:message key="cal.time" /></TH>
		<TH><bean:message key="cal.desc" /></TH>
	</TR>
	
	<%@ page language="java" import="org.hibernate.Session" %>
	<%@ page language="java" import="sessionfactory.HibernateSessionFactory" %>
	<%@ page language="java" import="java.util.List" %>
	

	<FORM METHOD=POST ACTION="ViewPlanning.do">
		<% for(int i = 0; i < table.getEntries().getRows(); i++) {
			   entr = table.getEntries().getEntry(i);

		Session sessionBD = HibernateSessionFactory.getSessionFactory().openSession (); 
		String req = "From Entry as e where e.hour='" + entr.getHour() + "'"
						+ "And e.date='" + AddEventAction.stringToDateSQL(table.getDate()) + "'"
						+ "And e.idEmploye ='" + session.getAttribute("idOfEmploye") + "'"; 
		List<Entry> l = sessionBD.createQuery(req).list ();
		%>

		<TR class="planning">
			<% String msghour = "cal."+entr.getHour(); %>
			
			<TD>
				<A href=Cal2.do?time=<%= entr.getHour() %>>
				<bean:message key="<%= msghour %>" /></A>
			</TD>
			
			<TD bgcolor=<%= entr.getColor() %>>
				<% if (l.size () != 0 ) 
						out.print(util.HTMLFilter.filter(l.get(l.size() - 1).getDescription())); 
					else
						out.print(util.HTMLFilter.filter(entr.getDescription()));
				%>
			</TD>
	</FORM>
		</TR>
		<% } %>
	
</TABLE>

<br>
<%
	} else {
%>
<font size=5>You must enter your name and email address correctly.</font>
<%
	}
%>

